package com.zfast.forge.pojo.bo;

import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.zfast.forge.navigation.Coordinate;
import com.zfast.forge.pojo.dto.Magic;
import com.zfast.forge.pojo.dto.Part;
import com.zfast.forge.pojo.dto.Player;
import com.zfast.forge.pojo.dto.Skill;
import com.zfast.forge.qlExpress.FormulaEnum;
import com.zfast.forge.qlExpress.QLExpressUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author zgn
 * @Description: PlayerInstance
 * @date 2024/3/1 0001
 */
@Data
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "PlayerInstance", description = "玩家运行实例")
public class PlayerInstance extends Player {
    @ApiModelProperty("站位")
    Coordinate stand;

    @ApiModelProperty("羽毛球_速度向量")
    Coordinate speed;

    @ApiModelProperty("羽毛球_加速度向量")
    Coordinate acceleration;

    @ApiModelProperty("角色信息")
    Part part;

    @ApiModelProperty("体力")
    Double hp;

    @ApiModelProperty("公式解析器")
    ExpressRunner runner;

    @ApiModelProperty("主动技能")
    List<Magic> magics;

    @ApiModelProperty("被动技能")
    List<Skill> skills;

    @ApiModelProperty("场地区域")
    Integer fieldSide;

    /**
     * 通过对手的反应时间计算飞行落地
     * @author  zgn
     * @date    2024/3/6 0006
     * @param	time 对手的反应时间
     * @return	com.zfast.forge.navigation.Coordinate
     */
    public Coordinate calculateFinalPosition(BigDecimal time) {
        DefaultContext<String, Object> context = new DefaultContext();

        context.put("initial", stand);
        context.put("Vx", speed.x);
        context.put("Vy", speed.y);
        context.put("Vz", speed.z);
        context.put("Ax", acceleration.x);
        context.put("Ay", acceleration.y);
        context.put("Az", acceleration.z);
        context.put("t", time);

        return (Coordinate) QLExpressUtil.execute(FormulaEnum.MovingPoint, context, runner);
    }

    public BigDecimal calculateRunTime() {
        DefaultContext<String, Object> context = new DefaultContext();

        context.put("Tr", this.getReaction());
        context.put("Ts", this.getResponse());

        return (BigDecimal) QLExpressUtil.execute(FormulaEnum.RunTime, context, runner);
    }
}
